<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 25. <数组练习>数组转换
        const input = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
        const output = [
            {
                x: 1,
                y: 2,
                z: 3,
            },
            {
                x: 4,
                y: 5,
                z: 6,
            },
            {
                x: 7,
                y: 8,
                z: 9,
            },
            {
                x: 10,
                y: 11,
                z: 12,
            },
            {
                x: 13,
                y: 14,
                z: 15,
            },
        ];


        // ⭐
        function transform(input) {
            const res = [];
            for (let i = 0; i < input.length; i += 3) {
                res.push({
                    x: input[i],
                    y: input[i + 1],
                    z: input[i + 2],
                });
            }
            return res;
        }
        console.log(transform(input));
    </script>
</body>
</html>